package com.joysw.ui;

import butterknife.ButterKnife;
import butterknife.InjectView;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.framework.Platform.ShareParams;

import com.joysw.R;
import com.joysw.ui.adapter.MyGridAdapter;
import com.joysw.view.NoScrollGridView;
import com.joysw.view.TitleBarView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;

/**   
 * @Title: FenXiangActivity.java 
 * @Package com.joysw.ui 
 * @Description: 发送共享页面
 * @author LIMINGYAN  
 * @date 2015年3月28日 上午7:35:57 
 * @version V1.0   
 */
public class FenXiangActivity extends BaseActivity{
	
	@InjectView(R.id.fenxiang_title_bar)
	TitleBarView mTitleBar;
	@InjectView(R.id.fenxiang_goods_details)
	NoScrollGridView mGridView;
	
	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);
		setContentView(R.layout.activity_fenxiang);
		ButterKnife.inject(this);
		
		initView();
	}
	
	private void initView(){
		mTitleBar.setCommonTitle(View.VISIBLE, View.VISIBLE, View.VISIBLE);
		mTitleBar.setTitleText(R.string.fenxiang_detail_title);
		mTitleBar.setBtnLeft(R.drawable.back, R.string.back);
		mTitleBar.setBtnRightText(R.string.fx_detail_right_text);
		mTitleBar.setBtnLeftOnclickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		mTitleBar.setBtnRightOnclickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// 跳转到微信发送朋友圈的页面
				showShare();
			}
		});
		loadGridImageData();//加载表格的图片
	}
	
	private void loadGridImageData(){
		final String[] urls = {"http://pic8.nipic.com/20100707/3613807_154427009099_2.jpg",
				"http://pic8.nipic.com/20100703/3613807_154652093501_2.jpg",
				"http://pic6.nipic.com/20100421/4074953_094348465112_2.jpg",
				"http://pic6.nipic.com/20100401/4589785_202322000442_2.jpg",
				"http://g.hiphotos.bdimg.com/album/s%3D680%3Bq%3D90/sign=ccd33b46d53f8794d7ff4b26e2207fc9/0d338744ebf81a4c0f993437d62a6059242da6a1.jpg",
				"http://g.hiphotos.bdimg.com/album/s%3D680%3Bq%3D90/sign=ccd33b46d53f8794d7ff4b26e2207fc9/0d338744ebf81a4c0f993437d62a6059242da6a1.jpg",
				"http://f.hiphotos.bdimg.com/album/s%3D680%3Bq%3D90/sign=6b62f61bac6eddc422e7b7f309e0c7c0/6159252dd42a2834510deef55ab5c9ea14cebfa1.jpg",
				"http://g.hiphotos.bdimg.com/album/s%3D680%3Bq%3D90/sign=e58fb67bc8ea15ce45eee301863b4bce/a5c27d1ed21b0ef4fd6140a0dcc451da80cb3e47.jpg",
				"http://c.hiphotos.bdimg.com/album/s%3D680%3Bq%3D90/sign=cdab1512d000baa1be2c44b3772bc82f/91529822720e0cf3855c96050b46f21fbf09aaa1.jpg"};
	
		if(urls!=null && urls.length>0){
			mGridView.setVisibility(View.VISIBLE);
			mGridView.setAdapter(new MyGridAdapter(urls, FenXiangActivity.this));
			mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

				@Override
				public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
					imageBrower(position,urls);
				}
			});
		}
	}
	
	private void imageBrower(int position, String[] urls) {
		Intent intent = new Intent(FenXiangActivity.this, ImagePagerActivity.class);
		// 图片url,为了演示这里使用常量，一般从数据库中或网络中获取
		intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_URLS, urls);
		intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_INDEX, position);
		FenXiangActivity.this.startActivity(intent);
	}
	
	private void showShare() {
		ShareSDK.initSDK(this);
		Platform plat = ShareSDK.getPlatform("WechatMoments");
		ShareParams sp = new ShareParams();
		sp.setText("美丽衣服 喜欢的前来抢购 点击有好礼物相送");
		sp.setShareType(Platform.SHARE_TEXT);
		sp.setShareType(Platform.SHARE_IMAGE);
		//sp.setImageArray(urls);
		sp.setImageUrl("http://pic6.nipic.com/20100401/4589785_202322000442_2.jpg");
		plat.share(sp);
	}
}
